﻿$idal_namespace_template= Get-Content -Raw ".\IDal_namespace.template";
$idal_interface_template= Get-Content -Raw ".\IDal_interface.template";
$authorTemplate=Get-Content -Raw ".\Author.template";
$cnreg=[regex]"(?<=class\s+)(\w+)";
[System.DateTime]$time=Get-Date -Format "yyyy/MM/dd hh:mm:ss"
$year=$time.ToString('yyyy');
$config=Test-Path "./config.txt";
if($config)
{
   $lasttime= Get-Content "./config.txt";
   $time=[datetime]::Parse($lasttime);
}
ls "../Model" |Where-Object {$_.FullName.EndsWith(".cs")}|Select-Object{

      $name=$_.BaseName;
   $srcfile=$_.FullName;
   [string]$this_content=Get-Content $srcfile;
   $result=$cnreg.Matches($this_content);
   $class_content="";
   for($x=0;$x -lt $result.Count;$x++)
   {
        $class_content+=$idal_interface_template.Replace("{{name}}",$result[$x].Value)
   }
   [string]$allcontent=$idal_namespace_template.Replace("{{interface}}",$class_content);
   $fullname="I"+$name+"Dal.cs";
   $newfullname="..\..\DAL\IDal\"+$fullname;
   $hasfile=Test-Path $newfullname;
   #如果文件存在就删除文件然后新建，重建所有文件
  if($hasfile)
   {
     Remove-Item $newfullname;
   }
	[string]$content=$authorTemplate.Replace("{{year}}",$year).Replace("{{filename}}",$fullname).Replace("{{time}}",$time).Replace("{{namespace}}","DAL.IDal").Replace("{{content}}",$allcontent)
   New-Item  -ItemType File -Path "..\..\DAL\IDal\" -Name $fullname -Value $content
 

   <#  ----------------------------------------------------
   #只新建新添加的文件
   if($hasfile)
   {
        #exit
   }
   else
   {
        New-Item  -ItemType File -Path "..\..\DAL\IDal\" -Name $fullname -Value $allcontent
   }#>


   
 
 
}
[string]$date=Get-Date -Format "yyyy/MM/dd hh:mm:ss";
$isexsits=Test-Path "config.txt";
if($isexsits)
{
  Remove-Item "./config.txt"
}
New-Item -Name "config.txt" -Value  $date

